﻿/// <reference path="../../../../Sustainalytics.EsgRatings.UI/modules/EsgRatings/utility/EsgUtility.ts" />
module Sustainalytics.Governance {

    import Common = Sustainalytics.Common;
    import Company = Sustainalytics.Company;
    import LRTM = Sustainalytics.LRTM;
    import Research = Sustainalytics.Research;
    import EsgUtility = Sustainalytics.EsgRatings.EsgUtility;

    export class SummaryOverallPerformanceController {

        // employee in charge with respective industry
        public companyOverall: GovernanceCompanyOverallDto;
        public assesmentList: string[] = ['Leader', 'Outperformer', 'Average Performer', 'Underperformer', 'Laggard'];
        public outlookList: string[] = ['Negative', 'Neutral', 'Positive'];
        private govProfile: GovernanceProfileController;
        public notFoundMessage: string;
        public $routeParams: any;
        public regionalPercentileOrdinal:string;

        //private userId: string;
        //private accountId: string;

        constructor(
            private $rootScope: ng.IScope,
            protected $scope: Company.ICompanyBasedScope,
            protected $q: ng.IQService,
            protected $sce: ng.ISCEService,
            protected $timeout: ng.ITimeoutService,
            protected $location: ng.ILocationService,
            protected RoutingService: Routing.IRoutingService,
            protected CompanyService: Company.ICompanyService,
            protected GovernanceCompanyProfileService: GovernanceCompanyProfileService,
            protected LongRunningTaskManagerService: LRTM.LongRunningTaskManagerService,
            private NumberUtilityService: Common.NumberUtilityService) {

            
            var ctx = this;
            ctx.govProfile = this.$scope['governancectrl'];
            ctx.govProfile.issueSelect = null;
            ctx.getOverallPerformance();
        }

        // get GovernanceCompanyOverallDto
        private getOverallPerformance(): ng.IPromise<GovernanceCompanyOverallDto> {
            var ctx = this;

            var promise = ctx.GovernanceCompanyProfileService.getCompanyCgOverallPerformance(ctx.govProfile.company.id);
            ctx.$rootScope['loading'] = true;
            promise.then(function (res: any) //GovernanceProfileDto or 7000 or 7001
            {
                if (res.errCode != undefined) {
                    console.log(res.message);
                }
                else {
                    ctx.$timeout(function () {
                        ctx.$scope.$apply(function () {
                            ctx.companyOverall = res;
                            ctx.companyOverall.assementStr = EsgUtility.getEsgPositionName(ctx.companyOverall.assesment);
                            ctx.companyOverall.outlookStr = EsgUtility.getEsgOutlookTypeName(ctx.companyOverall.outlook);
                            ctx.regionalPercentileOrdinal = ctx.NumberUtilityService.getOrdinalNameEnd(ctx.companyOverall.regionalPercentile);
                            ctx.$rootScope['loading'] = false;
                        });
                    });
                }
            }).finally(() => {
                ctx.$rootScope['loading'] = false;
            });

            return promise;
        }

        public RenderHTML(htmlCode: string) {
            var ctx = this;
            return ctx.$sce.trustAsHtml(htmlCode);
        }
    }

    angular.module(governanceModuleName).controller('SummaryOverallPerformanceController', ['$rootScope', '$scope', '$q', '$sce', '$timeout', '$location', 'RoutingService', 'CompanyService', 'GovernanceCompanyProfileService', 'LongRunningTaskManagerService','NumberUtilityService', SummaryOverallPerformanceController]);

} 